package com.blueheart.Test.util;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.List;

public class MainTest1<T> {

    List<T> param;

    public static void main(String[] args) throws Exception{

        Class clazz =  MainTest1.class;
        TypeVariable[] typeVariable = clazz.getTypeParameters();

        // 1
        Field field = clazz.getDeclaredField("param");
        ParameterizedType arrayType = (ParameterizedType)field.getGenericType();
        // interface List<E> 的泛型类型E被T,具体化，因此其被识别为 TypeVariable
        TypeVariable variable1 = (TypeVariable)arrayType.getActualTypeArguments()[0];

        // 2
        ParameterizedType type = (ParameterizedType)SubTest.class.getGenericSuperclass();
        TypeVariable variable2 = (TypeVariable)type.getActualTypeArguments()[0];
    }

    static class SubTest<R> extends MainTest1<R>{

    }

}
